/* eslint-disable no-shadow */
export function count({ search }) {
  return RSocket.rr({
    route: 'biz.activities.count',
    args: { search },
  });
}

export function search({ search, pg }) {
  return RSocket.rs({
    route: 'biz.activities',
    args: { search, pg },
  });
}

export function get(id) {
  return RSocket.rr({
    route: `biz.activities.${id}`,
  });
}

export function update(channel) {
  return RSocket.rr({
    route: 'biz.activities.update',
    data: channel,
  });
}

export function create(channel) {
  return RSocket.rr({
    route: 'biz.activities.create',
    data: channel,
  });
}

export function remove(id) {
  return RSocket.rr({
    route: `biz.activities.${id}.delete`,
  });
}

/**
 * @description 获取公司
 * @param {*} args 参数
 * @returns array
 */
export function getCompany(args) {
  return RSocket.rs({
    route: 'companys',
    args: { ...args },
  });
}

/* 获取扫码链接 */
export function addProfitShare(type, targetId, period) {
  return RSocket.rr({
    route: 'commons.profit-share-account.bind',
    args: {
      targetType: type,
      targetId,
      period,
    },
  });
}

/**
* 获取酒店价格方案
* @param {*} '
*/
export async function getChanelPrice(id) {
  try {
    return await RSocket.rr({ route: `dmn.rules.channel-price-${id}.docs-by-type.TPricePlan` });
  } catch (__) {
    return await RSocket.rr({ route: 'dmn.rules.channel-price.docs-by-type.TPricePlan' });
  }
}

/**
 * 上传规则文件
 * @param {Buffer} fileData ;
 * @returns 成功返回字节数，否则异常
 */
export function uploadRule(fileData) {
  return RSocket.rc({
    route: 'dmn.rules.surcharge.upload',
    data: fileData,
    logLevel: 'trace',
  });
}

export function getTopItems(dictId) {
  return RSocket.rs({
    route: `dicts.${dictId}.items.top`,
  });
}

/**
 * @description 获取包车订单数量
 * @returns true
 */
export function getOrderCount({ search }) {
  return RSocket.rr({
    route: 'orders.search.count',
    args: { search },
  });
}

/**
 * 获取指定用户
 * @param {*} args
 */
export function getUserMobile(mobile) {
  return RSocket.rr({
    route: `users.bymobile.${mobile}`,
  });
}

/**
 * 获取申领表
 * @param {*} args
 */
export function getCouponAPPlies({ search }) {
  return RSocket.rs({
    route: 'biz.coupon.applies',
    args: { search, pg: { size: 999 } },
  });
}

/**
 * 批次申领
 * @param {*} args
 */
export function batchApply(data) {
  return RSocket.rr({
    route: 'biz.coupon.applies.apply',
    data,
  });
}

/**
 * 批次追加
 * @param {*} args
 */
export function batchApplyAppend(id, quantity) {
  return RSocket.rr({
    route: `biz.coupon.applies.${id}.append`,
    args: {
      quantity,
    },
  });
}

/**
 * 批次追加  新
 * @param {*} args
 */
export function activityApplyAppend(activityId, data) {
  return RSocket.rr({
    route: `biz.coupon.applies.${activityId}.append`,
    args: {
      ...data,
    },
  });
}

/**
 * 客服批次追加
 * @param {*} args
 */
export function customerBagsAppend(id, quantity) {
  return RSocket.rr({
    route: `biz.coupon.customer.bags.${id}.append`,
    args: {
      quantity,
    },
  });
}

/**
 * 获取卡券包
 * @param {*} args
 */
export function getCouponBags({ search }) {
  return RSocket.rs({
    route: 'biz.coupon.customer.bags',
    args: {
      search,
      pg: { size: 999, page: 0, sort: ['crDate;desc'] },
    },
  });
}

/**
 * 获取员工卡包
 * @param {*} args
 */
export function getClientCouponBags({ search }) {
  return RSocket.rs({
    route: 'biz.coupon.bags',
    args: {
      search,
      pg: { size: 999, page: 0, sort: ['crDate;desc'] },
    },
  });
}

/**
 * 客服代发
 * @param {*} args
 */
export function substitutionCoupon(data) {
  return RSocket.rr({
    route: 'biz.activities.replace.distribute',
    data: {
      ...data,
    },
  });
}

// eslint-disable-next-line no-shadow
export function getCoupons({ search }) {
  return RSocket.rs({
    route: 'biz.coupon.batches',
    args: { search, pg: { size: 999, page: 0, sort: ['crDate;desc'] } },
  });
}

// eslint-disable-next-line no-shadow
export function getCouponsApplies({ search }) {
  return RSocket.rs({
    route: 'biz.coupon.applies',
    args: { search, pg: { size: 999, page: 0, sort: ['crDate;desc'] } },
  });
}

// eslint-disable-next-line no-shadow
export function sendCoupon(data) {
  return RSocket.rr({
    route: 'biz.activities.distribute.customer',
    data: { ...data },
  });
}

// eslint-disable-next-line no-shadow
export function getActivities({ search }) {
  return RSocket.rs({
    route: 'biz.activities',
    args: { search, pg: { size: 999, page: 0, sort: ['crDate;desc'] } },
  });
}

/**
 * 获取发放客服活动下的卡券
 * @param {*} params
 * @returns
 */
export function getCouponInfo(params) {
  return RSocket.rs({
    route: 'biz.activities.statistics.customer',
    args: { ...params },
  });
}

/**
 * 获取普通活动下的卡券
 * @param {*} params
 * @returns
 */
export function getCouponInfoNormal(params) {
  return RSocket.rs({
    route: 'biz.activities.statistics.normal',
    args: { ...params },
  });
}

/**
 * 日志流水分页条件查询
 * @param {}
 */
export function getLogs({ search }) {
  return RSocket.rs({
    route: 'logs',
    args: {
      search,
      pg: { page: 0, size: 100, sort: ['ts;desc'] },
    },
  });
}

/**
 * @description 获取活动规则
 * @returns true
 */
export function getActivityCfg(id) {
  return RSocket.rr({
    route: `dmn.rules.activity-${id}.exec.cfg`,
    data: {
      order: {},
      params: {},
    },
  });
}

/**
 * @description 获取卡券规则
 * @returns true
 */
export function getCouponCfg(id) {
  return RSocket.rr({
    route: `dmn.rules.coupon-${id}.exec.cfg`,
    data: {
      order: {},
      params: {},
    },
  });
}

/**
 * @description 获取订单ids集合
 * @returns true
 */
export function getIds(args) {
  return RSocket.rr({
    route: 'biz.coupon.bags.ids',
    args: {
      ...args,
    },
  });
}

/**
 * 客服已申领批次的数量
 * @param {*} param0
 * @returns
 */
export function getBatchApply(args) {
  return RSocket.rs({
    route: 'biz.activities.statistics.apply',
    args: {
      ...args,
    },
  });
}

/**
 * 获取普通活动下的金额
 * @param {*} param0
 * @returns
 */
export function getNormalPrices(args) {
  return RSocket.rr({
    route: 'biz.activities.statistics.normal.price',
    args: {
      ...args,
    },
  });
}

/**
 * 获取客服活动金额统计
 * @param {*} param0
 * @returns
 */
export function getCustomerPrices(args) {
  return RSocket.rr({
    route: 'biz.activities.statistics.customer.price',
    args: {
      ...args,
    },
  });
}

/**
 * 获取指定批次信息
 * @param {*} param0
 * @returns
 */
export function getBatchId(id) {
  return RSocket.rr({
    route: `biz.coupon.batches.${id}`,
  });
}

// 发送通知
export function sendNotify(args) {
  return RSocket.rr({
    route: 'commons.system.send',
    args: {
      ...args,
    },
  });
}

// 发放卡券包
export function sendCouponBag(data) {
  return RSocket.rr({
    route: 'biz.activities.distribute',
    data: {
      ...data,
    },
  });
}

// 发放卡券包
export function couponTransfer(data) {
  return RSocket.rr({
    route: 'biz.activities.transfer',
    data: {
      ...data,
    },
  });
}

/**
 * 获取默认客服列表
 * @param {*} args
 * @returns
 */
export function getCustomerService({ search }) {
  return RSocket.rs({
    route: 'roles.service.members',
    args: { search, pg: { page: 0, size: 999 } },
  });
}

/**
 * 查询该活动中的客服信息
 * @param {*} args
 * @returns
 */
export function getActivityCustomer(args) {
  return RSocket.rs({
    route: 'biz.activities.customer',
    args: { ...args, pg: { page: 0, size: 999 } },
  });
}

/**
 * @func 获取二维码
 */
export function getQCexterior(args) {
  return RSocket.rs({
    route: `wx.${global.getEnvCfg().travel}.post.binary`,
    args: {
      uri: '/wxa/getwxacode',
      body: {
        ...args,
        width: 800,
      },
    },
    binary: true,
  });
}

export function getCommandCode(data) {
  return RSocket.rr({
    route: 'biz.codes.generate',
    data: {
      ...data,
    },
  });
}

export function getSceneInfo({ search, pg }) {
  return RSocket.rs({
    route: 'biz.scenes.statistics',
    args: {
      search,
      pg,
    },
  });
}

export function getActivesList({ data, pg }) {
  return RSocket.rs({
    route: 'biz.actives.list.graphs',
    data,
    pg,
  });
}

export function getActivesStatistic({ data }) {
  return RSocket.rr({
    route: 'biz.actives.statistics.graphs',
    data,
  });
}
